import 'dart:collection';

import 'package:flutter_syt/starter/env_provider.dart';
import 'package:flutter_syt/starter/processor.dart';
import 'package:flutter_syt/starter/starter_exception.dart';

mixin Registry<T> {
  Map<Type, T> _registryMap = LinkedHashMap();

  void register(Type type, T value);

  T getByType(Type type) {
    if (!_registryMap.containsKey(type)) {
      throw IllegalStateException("Cannot find type");
    }
    return _registryMap[type]!;
  }

  Iterable<Type> getAll() => _registryMap.keys;
}

class EnvProviderRegistry with Registry<EnvProvider> {
  @override
  void register(Type type, EnvProvider provider) {
    _registryMap[type] = provider;
  }
}

class ProcessorRegistry with Registry<Processor> {
  @override
  void register(Type type, Processor value) {
    _registryMap[type] = value;
  }
}
